﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Common;
using AspNetCs.Bll;
using AspNetCs.Model;
using AspNetCs.Enumerations;
using AspNetCs.Enumerations.Channel_Enum;

public partial class Users_SelectNetMuTemplate : BasePage
{
    protected int id = 0;
    protected NetMuBLL bll = new NetMuBLL();
    protected NetMu_Model model = new NetMu_Model();
    protected AspNetCs.Bll.Temple templateBLL = AspNetCs.Bll.TempleBll.CreateNew;


    protected void Page_Load(object sender, EventArgs e)
    {
        CheckUserExit("Login.Aspx", "请您登录", true);
        if (Request["Id"] != null)
        {
            id = StringHelper.isNumber_int(Request["Id"].ToString());
        }
        if (id <= 0)
        {
            ShowMsgBack("参数传递错误！");
            Response.End();
        }
        model = bll.getNetMuDetailInfo(id);

        //Response.Write(model.GetPwd);

        Base_CurrPath = Base_CurrPath + " >> 会员管理中心 >> 公墓管理 >>板板选择";
        CheckUserExit("Login.Aspx?ReUrl=" + configInfo.InstallDir + "Users/SelectNetMuTemplate_" + id + ".Aspx", "", true);
    }

    /// <summary>
    /// 获得创建公墓需要的点数
    /// </summary>
    /// <param name="netMuType">墓类型</param>
    /// <returns></returns>
    protected int CreateNetMuPoint(NetMuTypeEnum netMuType)
    {
        int point = 0;
        switch (netMuType)
        {
            case NetMuTypeEnum.单人墓:
                point = configInfo.OnegravestonePoint;
                break;
            case NetMuTypeEnum.双人墓:
                point = configInfo.TwoGravestonePoint;
                break;
        }
        return point;
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {

        Users userBll = Users_Bll.CreatNew;
        int UserId = Base_GetUserInfo.UserId;
        //int needPoint = CreateNetMuPoint(NetMuTypeEnum(model.MuType));
        int TemplatePoint = StringHelper.isNumber_int(Request["hldTemplePoint"]);
        int TempId = StringHelper.isNumber_int(Request["templateId"]);
        if (TempId == model.TemplateId)
        {
            Response.Write("<script>alert('保存成功!');location.href='SelectNetMuTemplate_" + id + ".Aspx';</script>");
            return;
        }
        if (UserId != 0)
        {
            if (TemplatePoint != 0)
            {
                if (TemplatePoint <= (int)Base_GetUserInfo.Point)
                {

                    Temple_Model TmpMd = templateBLL.GetModel(TempId);
                    if (TmpMd.Id > 0)
                    {
                        Point_Log_Model PointMd = new Point_Log_Model();
                        PointMd.Addtime = DateTime.Now;
                        PointMd.NetIp = StringHelper.Ip();
                        PointMd.Point = TemplatePoint;
                        PointMd.Readme = "用户修改" + EnumDescription.GetFieldText(Channel_Type.gravestone) + "[" + model.MuName + "]的模板为" + TmpMd.TempleName + "，扣除点数" + TemplatePoint + "点";
                        PointMd.UserId = UserId;
                        Point_Log_Bll.CreateNew.Add(PointMd);
                    }
                    else
                    {
                        Response.Write("<script>alert('保存失败,当前模板不存在!');location.href='SelectNetMuTemplate_" + id + ".Aspx';</script>");
                        return;
                    }
                }
                else
                {
                    Response.Write("<script>alert('保存失败,用户点数不足!');location.href='SelectNetMuTemplate_" + id + ".Aspx';</script>");
                    return;
                }


            }
            NetMu_Bll.CreatNew.filterUpdate(" TemplateId= " + TempId, " id=" + id);
        }
        else
        {
            CheckUserExit("Login.Aspx?ReUrl=" + configInfo.InstallDir + "Users/SelectNetMuTemplate.Aspx", "请您登录", true);
        }
        Response.Write("<script>alert('保存成功!');location.href='SelectNetMuTemplate_" + id + ".Aspx';</script>");

    }

}
